import {
	createVNode,
	render
} from "vue"
import Confirm from "./chatCard.vue";
let mountNode = null
//传进来参数

export default (options) => {
	const duration = options.duration | 2000;
	return new Promise((reslove, reject) => {
		if(mountNode || !options.isShow) {
			render(null, mountNode)
			mountNode = null
		}
		const accept = () => {
			render(null, mountNode)
			mountNode.remove();
			reslove()
		}
		
		const refuse = () => {
			render(null, mountNode);
			mountNode.remove();
			reject()
		}
		const VNode = createVNode(Confirm, {
			...options,
			duration,
			accept,
			refuse
		})
		mountNode = document.createElement("div")
		document.body.appendChild(mountNode)
		render(VNode, mountNode)
	})
}
